<template>
  <div class="main" ref="remove">
    <div class="admissionWrap">
      <select-picker
        :titles="areas"
        v-on:showPick1="showPicks"
        v-on:showPickCty1="showPicksCty"
        :pov="value1[0]"
        :cty="value2[0]"
      ></select-picker>
      <div class="otherSpc">
        <admission-line :lineData="lineData1" :titleData="titleData1"></admission-line>
      </div>
      <select-picker
        :pts="true"
        titles="专业录取分数线"
        v-on:showPick1="showPicks1"
        v-on:showPickCty1="showPicksCty1"
        v-on:showPickType1="showPicksType"
        :pty="value3[0]"
        :pov="value4[0]"
        :cty="value5[0]"
      ></select-picker>
      <admission-line :lineData="lineData2" :titleData="titleData2" :ssreStyle="true"></admission-line>

      <!-- <div style="width: 100%;height: 94px;"></div> -->
    </div>
    <popup-picker
      :show.sync="showPopupPicker"
      :show-cell="false"
      :data="list1"
      v-model="value1"
      @on-show="onShow"
      @on-hide="onHide"
      @on-change="onChange"
    ></popup-picker>
    <popup-picker
      :show.sync="showPopupPicker1"
      :show-cell="false"
      :data="list2"
      v-model="value2"
      @on-change="onChange1"
    ></popup-picker>
    <popup-picker
      :show.sync="showPopupPicker2"
      :show-cell="false"
      :data="list3"
      v-model="value3"
      @on-change="onChange2"
    ></popup-picker>
    <popup-picker
      :show.sync="showPopupPicker3"
      :show-cell="false"
      :data="list4"
      v-model="value4"
      @on-change="onChange3"
    ></popup-picker>
    <popup-picker
      :show.sync="showPopupPicker4"
      :show-cell="false"
      :data="list5"
      v-model="value5"
      @on-change="onChange4"
    ></popup-picker>
  </div>
</template>
<script>
import admissionLine from "~/components/admissionLine";
import selectPicker from "~/components/selectPicker";
import { getBatch, examinees, majorExaminees } from "~/api/college";
import ls from "store2";
import { PopupPicker } from "vux";

import { format } from "~/plugins/filter";
export default {
  head: {
    title: "录取"
  },
  components: {
    PopupPicker,
    admissionLine,
    selectPicker
  },
  props: {
    // lineData1:Array
  },
  data() {
    return {
      areas: "院校分数线",
      titleData1: ["招生批次", "最低分", "最低位次", "计划数", "投档人数"],
      lineData1: [],
      titleData2: [
        "招生专业",
        "最高分",
        "最低分",
        "平均分",
        "最低位次",
        "录取数"
      ],
      lineData2: [],
      godown: false,

      showPopupPicker: false,
      showPopupPicker1: false,
      showPopupPicker2: false,
      showPopupPicker3: false,
      showPopupPicker4: false,
      list1: [["2018", "2017", "2016"]],
      list2: [["理科", "文科"]],
      list3: [
        // ['本科一批', '本科二批', '本科三批', '专科批']
      ],
      list4: [["2018", "2017", "2016"]],
      list5: [["理科", "文科"]],
      value1: ["2018"],
      value2: ["理科"],
      value3: ["本科一批"],
      value4: ["2018"],
      value5: ["理科"]
    };
  },
  mounted: function() {
    this.$vux.loading.show({
      text: "正在加载"
    });
    this.showSortLine();
    this.showMajorLine();
    setTimeout(() => {
      this.showPici();
    }, 50);
  },
  destroyed() {},
  watch: {},
  methods: {
    showPici() {
      getBatch({
        academyCode: ls.get("applsData").academyCode + "",
        province: ls.get("userArea")
      })
        .then(res => {
          if (res.code === "0") {
            console.log("res2", res);
            let ary = [];
            // let are=[];
            res.data.forEach(item => {
              ary.push(item);
            });
            this.list3.push(ary);
            this.value3[0] = res.data[0];
            this.$vux.loading.hide();
          }
        })
        .catch(error => {
          this.$vux.toast.text("暂无数据");
        });
    },
    showSortLine() {
      examinees({
            academyCode: ls.get("applsData").academyCode + "",
            type: this.value2[0],
            year: this.value1[0],
            province: ls.get("userArea")
          })
        .then(res => {
          if (res.code === "0") {
            this.areas = "院校分数线(" + ls.get("userArea") + ")";
            let datas = res.data;
            let ary = [];
            datas.forEach(item => {
              item.level ? (item.level = item.level) : (item.level = "--");
              item.minScore
                ? (item.minScore = item.level)
                : (item.minScore = "--");
              item.minRanking
                ? (item.minRanking = item.minRanking)
                : (item.minRanking = "--");
              item.numPlan
                ? (item.numPlan = item.numPlan)
                : (item.numPlan = "--");
              item.numArchive
                ? (item.numArchive = item.numArchive)
                : (item.numArchive = "--");
              ary.push({
                main: [
                  item.level,
                  item.minScore,
                  item.minRanking,
                  item.numPlan,
                  item.numArchive
                ]
              });
            });
            this.lineData1 = ary;
          }
          this.$vux.loading.hide();
        })
        .catch(error => {
          this.$vux.toast.text("服务器繁忙，请稍后再试");
          this.$vux.loading.hide();
        });
    },
    showMajorLine() {
      majorExaminees({
            academyCode: ls.get("applsData").academyCode + "",
            type: this.value5[0],
            year: this.value4[0],
            level: this.value3[0],
            province: ls.get("userArea")
          })
        .then(res => {
          if (res.code === "0") {
            let datas = res.data;
            let ary = [];
            datas.forEach(item => {
              item.majorName
                ? (item.majorName = item.majorName)
                : (item.majorName = "--");
              item.maxScore
                ? (item.maxScore = item.maxScore)
                : (item.maxScore = "--");
              item.minScore
                ? (item.minScore = item.minScore)
                : (item.minScore = "--");
              item.avgScore
                ? (item.avgScore = item.avgScore)
                : (item.avgScore = "--");
              item.minRanking
                ? (item.minRanking = item.minRanking)
                : (item.minRanking = "--");
              item.number ? (item.number = item.number) : (item.number = "--");
              ary.push({
                main: [
                  item.majorName,
                  item.maxScore,
                  item.minScore,
                  item.avgScore,
                  item.minRanking,
                  item.number
                ]
              });
            });
            this.lineData2 = ary;
          }
          this.$vux.loading.hide();
        })
        .catch(error => {
          this.$vux.toast.text("服务器繁忙，请稍后再试");
          this.$vux.loading.hide();
        });
    },
    showPicks() {
      this.showPopupPicker = true;
    },
    showPicks1() {
      this.showPopupPicker3 = true;
    },
    showPicksCty() {
      this.showPopupPicker1 = true;
    },
    showPicksCty1() {
      this.showPopupPicker4 = true;
    },
    showPicksType() {
      this.showPopupPicker2 = true;
    },

    onChange(val) {
      this.$vux.loading.show({
        text: "正在加载"
      });
      this.value1 = val;
      this.showSortLine();
    },
    onChange1(val) {
      this.$vux.loading.show({
        text: "正在加载"
      });
      this.value2 = val;
      this.showSortLine();
    },
    onChange2(val) {
      this.$vux.loading.show({
        text: "正在加载"
      });
      this.value3 = val;
      this.showMajorLine();
    },
    onChange3(val) {
      this.$vux.loading.show({
        text: "正在加载"
      });
      this.value4 = val;
      this.showMajorLine();
    },
    onChange4(val) {
      this.$vux.loading.show({
        text: "正在加载"
      });
      this.value5 = val;
      this.showMajorLine();
    },
    onShow() {
      console.log("on show");
    },
    onHide(type) {
      console.log("on hide", type);
    },
    goto(routerName, queryData) {
      this.$router.push({
        path: routerName,
        query: {
          type: queryData
        }
      });
    }
  },
  beforeDestroy() {}
};
</script>

<style lang="less">
.admissionWrap {
  width: 7.5rem;
  height: auto;
  background: #fff;
  padding-top: 0.2rem;
}

.vux-cell-box:not(:first-child):before {
  border-top: none !important;
}

// .vux-cell-box:not(:first-child):before
.otherSpc .admissionGezi .adSmallBox .adSmallLine span:nth-of-type(1) {
  text-align: center !important;
}
</style>
